package impresion;

import java.awt.Color;
import java.util.List;
import java.util.Vector;

import componentes.Tablero;

public class Impresora extends Thread{

	private List<List<Color>> lsColores = new Vector<List<Color>>(); 
	private PanelJuego panelJ;
	private int sleepTime;
	
	public Impresora(PanelJuego panelJ){
		this.panelJ = panelJ;
		sleepTime=1000;
	}
	
	public void cambiarSleepTimeDeImpresion(int n){
		sleepTime = n;
	}
	
	//Metodo de monitor para que no se pisen las impresiones
	public synchronized void imprimirTXT(Tablero t) throws InterruptedException{
		dormir();
		t.print();
	}
	
	public void dormir() throws InterruptedException{
		Thread.sleep(sleepTime);
	}

	public synchronized void imprimirGUI(Tablero t) throws InterruptedException{
		dormir();
		t.imprimir();
	}
	
	public synchronized void agregarAColaDeImpresion(List<Color> cs){
		lsColores.add(cs);
	}
	
	@Override
	public void run() {
		while(true){
			while(lsColores.size()>0){
				panelJ.setColores(lsColores.get(0));
				panelJ.repaint();
				panelJ.setVisible(true);
				lsColores.remove(0);
			}
		}
	}

}
